﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// 有两个列表，一个包含订单，一个包含客户。根据客户的 ID 将订单和客户连接起来，显示每个订单的客户姓名和订单金额。
namespace CS_BEGINNER_TO_PROFICIENT.STD.LinqSTD
{
    public class P5
    {
        public static void Execute()
        {
            List<Order> orders = new List<Order>
            {
                new Order { OrderId = 0, CustomerId = 1, Amount = 25.0M },
                new Order { OrderId = 1, CustomerId = 1, Amount = 22.0M },
                new Order { OrderId = 2, CustomerId = 2, Amount = 2523.0M },
                new Order { OrderId = 3, CustomerId = 3, Amount = 231.0M },
                new Order { OrderId = 4, CustomerId = 4, Amount = 2312.0M },
                new Order { OrderId = 5, CustomerId = 4, Amount = 908.0M },
                new Order { OrderId = 6, CustomerId = 2, Amount = 314.0M },
                new Order { OrderId = 7, CustomerId = 3, Amount = 9841.0M },
                new Order { OrderId = 8, CustomerId = 3, Amount = 1334.0M }
            };

            List<Custom> customs = new List<Custom>
            {
                new Custom { Name = "lisi", CustomerId = 1 },
                new Custom { Name = "zhangsan", CustomerId = 2 },
                new Custom { Name = "zhaosi", CustomerId = 3 },
                new Custom { Name = "wangwu", CustomerId = 1 }
            };

            var res = orders.Join(customs, o => o.CustomerId, c => c.CustomerId, (o, c) => new { CustomerName= c.Name, Amoumt = o.Amount });

            foreach (var i in res)
            {
                Console.WriteLine($"CustomerName: {i.CustomerName} Amoumt: {i.Amoumt}");
            }
        }
    }

    public class Order
    {
        public int OrderId { get; set; }
        public int CustomerId { get; set; }

        public decimal Amount { get; set; }
    }

    public class Custom
    {
        public int CustomerId { get; set; }
        public string Name { get; set; }
    }
}
